package com.cn.demo4.servlet.admin.nav;

import com.alibaba.fastjson.JSONObject;
import com.cn.demo4.model.NavModel;
import com.cn.demo4.service.INavService;
import com.cn.demo4.service.impl.NavServiceImpl;
import com.cn.demo4.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/nav/findById")
public class NavFindByIdServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.设置字符编码
        //2.得到前台传递来的id
        String idString = req.getParameter("id");
        //3.封装数据
        Integer id = Tool.stringToInt(idString);

        //4.调用逻辑服务层
        INavService iNewsService = new NavServiceImpl();
        //5.得到结果存入集合
        NavModel model = iNewsService.findById(id);
        //6.返回结果给前台
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("model",model);
        resp.getWriter().println(jsonObject);
    }
}
